<?php
function theme_widget_rob_good_slide(&$setting,&$render){
    $_return = false;
    switch ($setting['selector']) {
    case 'filter':
        parse_str($setting['goods_filter'],$goodsFilter);
        $goodsFilter['goodsOrderBy'] = $setting['goods_order_by'];
        $goodsFilter['goodsNum'] = (intval($setting['limit'])>0)?intval($setting['limit']):6;
        $_return = b2c_widgets::load('Goods')->getGoodsList($goodsFilter);
        //$_return = array_values($_return['goodsRows']);
        break;
    case 'select':
        $goodsFilter['goods_id'] = explode(",", $setting["goods_select"]);
		$goodsFilter['goodsNum'] = (intval($setting['limit'])>0)?intval($setting['limit']):6;		
        $goodsFilter['goodsOrderBy'] = $setting['goods_order_by'];
        $_return = b2c_widgets::load('Goods')->getGoodsList($goodsFilter);
        foreach (json_decode($setting['goods_select_linkobj'],1) as $obj) {
            if(trim($obj['pic'])!=""){
                $_return['goodsRows'][$obj['id']]['goodsPicL'] = 
                    $_return['goodsRows'][$obj['id']]['goodsPicM'] = 
                    $_return['goodsRows'][$obj['id']]['goodsPicS'] = $obj['pic'];
            }
            if(trim($obj['nice'])!=""){
                $_return['goodsRows'][$obj['id']]['goodsName'] = $obj['nice'];
            }
        }

        break;

    }
    $gids = array_keys($_return['goodsRows']);
    if(!$gids||count($gids)<1)return $_return;
    $mdl_product = app::get('b2c')->model('products');
    $products = $mdl_product ->getList('product_id, spec_info, price, freez, store, marketable, goods_id',array('goods_id'=>$gids,'marketable'=>'true'));
    // @zeng 2017.4.25 当前用户id
    $memberMolde=kernel::single('b2c_user_object');
    $member_id=$memberMolde->get_member_id();
    if($member_id)
    {
        $member_state=$memberMolde->get_member_state($member_id);
        $member_lv_id=$memberMolde->get_member_lv($member_id);
    }
    else
    {
        $member_state='-1';
        $member_lv_id='';
    }
    $data['info']=array('member_state'=>$member_state);
    //@zeng 2017.4.25 商品会员价
    $mlvpriceModel=kernel::single('b2c_goods_object');


    foreach ($products as $product) {

        $_return['goodsRows'][$product['goods_id']]['products'][] = $product;
        //@zeng 2017.4.25 商品会员价
        $_return['goodsRows'][$product['goods_id']]['products'][] = $data;//用户审核状态
        $mlv_price=$mlvpriceModel->get_member_lv_goods_price($product['goods_id'],$member_lv_id);
        if($mlv_price)
            $_return['goodsRows'][$product['goods_id']]['products'][] = array('mlv_price'=>$mlv_price);//会员价
        else
             $_return['goodsRows'][$product['goods_id']]['products'][] = array('mlv_price'=>$product['price']);//销售价
        //@mo add 2017年5月2日 14:50:55
         $member_id = kernel::single('b2c_user_object')->get_member_id();
         if(!empty($member_id))
         {
             $now_can_buy_this_goods_quantity = 0;
               $now_can_buy_this_goods_quantity = kernel::single('b2c_checkproduct_check')->can_buy_productid_quantity($product['product_id']);
            
             // 将小于触发值的数量提示去掉 add by hzk
               $getstartgiftnum = kernel::single('b2c_checkproduct_check')->getstartgiftnum('product_id',$product['product_id']);
			if($now_can_buy_this_goods_quantity < $getstartgiftnum){
              	$now_can_buy_this_goods_quantity = 999999;
              }
//			echo '<pre>';
//			echo '<br>==========<br>';
//			echo $getstartgiftnum;
//			echo '<br>==========<br>';
              if( $now_can_buy_this_goods_quantity!= -1 )  //@mo
              {
                $_return['goodsRows'][$product['goods_id']]['products'][] = array('type'=>app::get('b2c')->_('havegift'));
                $_return['goodsRows'][$product['goods_id']]['products'][] = array('maxbuy'=>$now_can_buy_this_goods_quantity);
              }else{
              	
                $_return['goodsRows'][$product['goods_id']]['products'][] = array('type'=>app::get('b2c')->_('nullgift'));
                $_return['goodsRows'][$product['goods_id']]['products'][] = array('maxbuy'=>'');
              }
          
        }

    }


// kernel::single('b2c_checkproduct_check')->set_good_cart($this->pagedata['aCart']);

	$_return['slideData'] = array();
	$col = ($setting['colums'])?$setting['colums']:6;//列数
	$_return['slidenum']=ceil(@count($_return['goodsRows'])/$col);
	for($i=0;$i<$_return['slidenum'];$i++){
		$_return['slideData'][] = array_slice($_return['goodsRows'],$i*$col,$col);
	}
    	//add by 黄智坤
       $add['isused'] = app::get('b2c')->getConf('system.member.IsUsed');
       $add['pernum'] = app::get('b2c')->getConf('system.product.per.num');
       $_return['add'] = $add;

       //add 这里是验证登录状态----未登录不显示商品价格 ---黄智坤06-19
		$userObject = kernel::single('b2c_user_object');
        if( $userObject->is_login()){
            $_return['check_login'] = 'login';
        }else{
        	$_return['check_login'] = 'nologin';
        }
        //end

//        $cur_url = $_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
//       $_return['cur_url'] = $cur_url;
//    
//    echo "<pre>";
//	print_r($_return);exit;
	return $_return;

    //var_dump($_return);
}
?>
